#include<iostream>
#include<queue>
using namespace std;

//
priority_queue<int,vector<int>,less<int>> Pquec;
priority_queue<int,vector<int>,greater<int>> Nquec;
priority_queue<int,vector<int>,less<int>> Pquep;
priority_queue<int,vector<int>,greater<int>> Nquep;

int main(){
    //freopen("in.txt","r",stdin);
    int Nc,Np;
    scanf("%d",&Nc);
    int tmp;
    for(int i=0;i<Nc;i++){
        scanf("%d",&tmp);
        if(tmp<0){Nquec.push(tmp);}
        else{Pquec.push(tmp);}
    }
    scanf("%d",&Np);
    for(int i=0;i<Np;i++){
        scanf("%d",&tmp);
        if(tmp<0){Nquep.push(tmp);}
        else{Pquep.push(tmp);}
    }
    int ans=0;
    while(!Pquec.empty() && !Pquep.empty()){
        int coupons=Pquec.top();Pquec.pop();
        int pro=Pquep.top();Pquep.pop();
        ans+=coupons*pro;
    }
    while(!Nquec.empty() && !Nquep.empty()){
        int coupons=Nquec.top();Nquec.pop();
        int pro=Nquep.top();Nquep.pop();
        ans+=coupons*pro;
    }
    printf("%d\n",ans);
}
